<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <title>我的钱包</title>

    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css"
          rel="stylesheet">    

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/static/js/global.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"></script>

    <style type="text/css">
        .main h5 a {
            position: absolute;
            right: 20px;
            font-size: 14px;
            bottom: 0px;
            display: inline-block;
            padding: 5px;
        }

        .table_list tbody tr {
            height: 35px;
            text-align: center;
        }
        .div1{
            margin-top: 14px;
    		border: solid #CCCCCC;
    		border-width: 1px 0px 0px 0px;
        }
        .td3{
        	
        	border-width:0px 1px 1px 0px; 
        	padding:10px 0px; width: 30%;
        	height: 120px;
        	}
        .enjoyA{
        	    color: orangered;
        	    font-size: 25px;
        	    margin-left: 26px;
        }
        .enjoyA:hover{color: orangered;}
        .enjoyB{
        	    color: #CCCCCC;
        	    font-size: 18px;
        	    margin-left: 26px;
        }
        .name1{
        	font-size: 18px;
        	margin-left: 12px;
        }
		.left ul li{
			
			*line-height:40px;
			
			*padding-left:20px;
		}
		
		.left ul li a, .left ul li a:hover{
			*color:#fff;
		}
		.list-tab li{
			*+padding:0px 10px 10px;
		}
		
		.btn{
			padding:2px 4px;
			font-size:12px !important;
			margin: 0 2px;
			*width:65px;
			*+padding:4px 0;
			*+padding-left:0;
			*+font-size:14px;
		}
		.name1 .btnn{
			*width:102px;
		}
		.lt{
			float:left;
		}
		.ui-pg-button{
			*background:#ccc;
		}
		.col-md-3{
			*width:100px;
		}
		.form-group{
			*overflow: hidden;
		}
		.pagination{
			*margin-left:50%;
		}
		.wrapper{
			*margin-left:270px;
		}
		#rName{
			*padding:0;
		}
		.wallet{
			font-size:18px;
			color:#111;
		}
		.wallet span{
			color:red;
			font-size:14px;
		}
		.wallet span span{
			font-size:20px;
		}
		.child{
			margin-right:10px;
			font-size:14px;
		}
		.name1 span{
		  margin-right:8px;
		}
		.name1 span span{
		  margin-left:2px;
		}
		.name1 .spa{
			font-size:20px;
			color:red;
			margin-right:100px;
		}
		
		.td{
			border-left:1px solid #CCCCCC; 
			border-right:1px solid #CCCCCC; 
		}
		.col-md-1{
			
		}
		.col-sm-3{
			
		}
		.col-md-3{
			padding-right:0;
		}
		.no_padding{
			padding-right:0;
		}
		.selectlabe2{
			width:100px !important\0;
		}
		.selectlabe1{
			width:90px !important;
		}
		.form-control{
			*+padding:0;
		}
		.form-action1{
			margin-left:0px;
			*+margin-left:0px;
		}
		#query,#resetForm{
			width:50px\0;
			height:26px !important;
			line-height:26px !important;
			*+line-height:22px !important;
			padding:0;
		}
		.form-lable{
			padding:6px 2px;
		}
		.form-control{
			height:30px !important;
		}
		.select2-container--default .select2-selection--single{
			height: 30px !important;
           line-height: 30px !important;
		}
		.selectdivs{
			width:160px !important;
		}
		.form-group {
			margin-bottom: 0px;
		}
    </style>
</head>
<body view="menu-item-4142">
<jsp:include page="../../top.jsp"></jsp:include>
<div class="right">
<div class="wrapper">
        <div class="panel panel-default">
            <table id="enjoyTable">
            <tr style="border-bottom:1px solid #ccc;">
            	<td class="td3" style="width: 40%;">
            	<div class="name1 wallet">我的钱包总额：<span><span id="balance"></span>元</span></div>
            	
            	<div class="name1">
	            	<span class="child">可用金额：<span id="valbalance"></span></span>
	            	<span class="child">冻结中金额:<span id="frzbalance"></span></span>
            	</div>
            	</td>
            	<td class="td3 td" style="width: 30%;">
            	<div class="name1">进行中的红包</div>
            	<div class="name1">
            		<span class="child spa" id="redenv"></span>           	
	            	<input type="button"  class="inButton btn btnn btn-success" style="padding-left:10px;padding-right:10px;" onclick="addQuato()" value="发定额红包">
	            	<input type="button"  class="inButton btn btnn btn-success" style="padding-left:10px;padding-right:10px;" onclick="addRandom()" value="发随机红包">
            	</div>
         
            	</td>
            	<td class="td3" style="width: 30%;">
            	<div class="name1">今日发放红包</div>
            	<div class="name1">
            		<span class="child spa" id="todayredenv"></span>
	            	
            	</div>
            	</td>
            </tr>
			</table>
            <div class="div1 panel-body">
                <form class="form-horizontal">
                       <div class="form-group">
                        <label class="selectlabe1 col-md-1 lt form-lable" >红包名称：</label>
                        <div class="selectdivs col-md-3 lt" >
                            <input id="rName" name="rName" type="text" class="form-control"/>
                        </div>
                       	<label class="selectlabe2 col-md-1  lt form-lable">红包类型：</label>
                        <div class="selectdivs col-md-3 lt">
                            <select name="status" id="mainretype" class="form-control col-md-1">
                                <option value="">请选择类型</option>
                                <option value="1">定额红包</option>
                                <option value="2">随机红包</option>
                            </select>
                        </div>
                       
                       	<label class="selectlabe2 col-md-1  lt form-lable">红包状态：</label>
                        <div class="selectdivs col-md-3 lt">
                            <select name="status" id="envstatus" class="form-control col-md-1">
                                <option value="">请选择状态</option>
                                <option value="1">未领取</option>
                                <option value="2">领取中</option>
                                <option value="3">已领完</option>
                                <option value="4">已下架</option>                                
                            </select>
                        </div>
                        
                        <div class="col-md-1 form-action lt no_padding">
                            <button class="btn btn-success form-control" id="query">查询</button>
                        </div>
                        <div class="col-md-1 form-action lt no_padding">
                            <button class="btn btn-success form-control" id="resetForm">清空</button>
                        </div>
                   	</div>        			
                </form>
            </div>
        </div>
	    <div class="jqGrid_wrapper">
	        <div id="jqGrid_operation" class="jg-grid">
	            <div class="jqGrid_operation" id="action">
				</div>
			<a style="font-size: 12px;color: #666;padding-left: 20px;font-weight: bolder;">红包发放记录</a>	           				
	        </div>
	        <table id="jqGrid"></table>
	        <div id="jqGrid_paper"></div>
	    </div>
	</div>
</body>
<script>

    $(document).ready(
            function () {

				$("#balance").html('${balance}');
				$("#valbalance").html('${valbalance}'+" 元");
				$("#frzbalance").html('${frzbalance}'+" 元");
				$("#redenv").html('${redenv}'+" 个");				
				$("#todayredenv").html('${todayNum}'+" 个红包，"+'${todayAmount}'+"元");
                $.jgrid.defaults.styleUI = "Bootstrap";
                $("#jqGrid").jqGrid(
                        {
                            url: "${pageContext.request.contextPath}/admin/redPacket_page.action",
                            mtype: 'POST',
                            datatype: "json",
                            height: 460,
                            autowidth: true,
                            shrinkToFit: true,
                            rowNum: 10,
                            rowList: [10, 20, 30],
                            colNames: ['序号', '红包名称', '红包类型', '红包状态', '红包有效期（天）', '发放时间段', '已领数量 / 红包总数（个）',
                                '已领金额 / 红包总金额（元）', '发放对象','操作'],
                            colModel: [{
                                name: "SID",
                                index: "SID",
                                key: true,
                                hidden: true
                            }, {
                                name: 'RNAME',
                                index: 'RNAME',
                                width: 60
                            },{
                                name: "MAINRETYPE",
                                index: "MAINRETYPE",
                                width: 30
                            }, {
                                name: 'ENVSTATUS',
                                index: 'ENVSTATUS',
                                width: 30
                            },{
                                name: 'EFFECTIVEDATE',
                                index: 'EFFECTIVEDATE',
                                width: 50
                            },{
                                name: 'PERIOD',
                                index: 'PERIOD',
                                width: 80
                            },{
                                name: 'RENUM',
                                index: 'RENUM',
                                width: 60
                            }, {
                                name: "REAMOUNT",
                                index: "REAMOUNT",
                                width: 60
                            }, {
                                name: 'ISSENDALL',
                                index: 'ISSENDALL',
                                width: 80
                            }, {
                                name: "SID",
                                index: "SID",
                                width: 100,
								align: "left",
                                formatter: function (cellvalue, options, rawObject) {
                                	var retur = '';
                                	if(cellvalue!=''){
                                	retur+='<input type="button" style="padding: 2px 10px;margin-left: 5px;" class="btn btn-success" value="领取记录 " onclick="receiveLog('+rawObject.SID+')"/>';
                                    retur+='<input type="button" style="padding: 2px 10px;margin-left: 5px;" class="btn btn-success" value="红包详情 " onclick="detail('+rawObject.SID+')"/>';
                                    if(rawObject.ENVSTATUS=='未领取' || rawObject.ENVSTATUS=='领取中'){
                                     	retur+='<input type="button" style="padding: 2px 10px;margin-left: 5px;"  class="btn btn-success" value="下架 " onclick="off('+rawObject.SID+')"/>';
                                     	}
                                	}
                                    	return retur;
                                      }
                            }],
                            sortname: 'sid',
                            rownumbers: true,
                            jsonReader: {
                                root: 'rows',
                                page: "page",
                                total: 'total',
                                records: "records",
                                repeatitems: false
                            },
                            pager: "#jqGrid_paper",
                            viewrecords: true,
                            multiselect: true,
                            hidegrid: false,
                            loadComplete: function(){
                        		var re_records = Number($("#jqGrid").getGridParam('records'));
                        		var page = Number($("#jqGrid").getGridParam('page'));
                        		var rows=Number($("#jqGrid").getGridParam('rowNum'));
                        		var num = re_records-(page-1)*rows;
                        		if(num < rows)
                        		{
                        			for(var i=num;i<rows;i++){
                        				$("#jqGrid").jqGrid("addRowData",(i+1),
                                				{ "SID":"", "RNAME":"", "MAINRETYPE":"", "ENVSTATUS":"", "EFFECTIVEDATE":"","PERIOD":"","RENUM":"","REAMOUNT":"","SID":""}
                        				,"");
                        			}
                        			$(".ui-paging-info").html(re_records-num+1 +" - "+re_records+"　共 "+re_records+" 条");
                        		}
                        		//自适应屏幕大小
                        	}
                        });
                $("#envstatus").select2({
                    "placeholder": "请选择类型",
                    "minimumResultsForSearch":-1
                });
                
                $("#mainretype").select2({
                    "placeholder": "请选择类型",
                    "minimumResultsForSearch":-1
                });                
                <!--查询-->
                jQuery("#query").click(query);
                jQuery("#resetForm").click(resetForm);
                var vtype =  '${vtype}';
                if(vtype=='1'){
                	addQuato();
                }else if(vtype=='2'){
                	addRandom();
                }
                
            });

    <!--刷新jqGrid表格数据-->
    function refreshGrid() {
        $("#jqGrid").trigger("reloadGrid");
    }
    function resetForm() {
        location.reload();
        return false;
    }
    function query() {
        var rName = $("#rName").val();
        var envstatus = $("#envstatus").val();
        var mainretype = $("#mainretype").val();
        $("#jqGrid").jqGrid('setGridParam', {
            url: "${pageContext.request.contextPath}/admin/redPacket_page.action",
            postData: {
                'rName': rName,
                'envstatus': envstatus,
                'mainretype': mainretype
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入*/
        return false;
    }
    function addQuato2(){
    	layer.open({
            type: 2,
            title: ['定额红包', 'font-weight:bold'],
            shadeClose: true, //点击遮罩关闭层
            area: ['1100px', '600px'],
            scrollbar: false,
            content: '${pageContext.request.contextPath}/admin/redPacket_addQuotaView.action'
        });
    }
    function addQuato(){
			window.location.href="${pageContext.request.contextPath}/admin/redPacket_addQuotaView.action"; 
    }
	function addRandom(){
			window.location.href="${pageContext.request.contextPath}/admin/redPacket_addRandomView.action"; 
    }
    function addRandom2(){
    	layer.open({
            type: 2,
            title: ['随机红包', 'font-weight:bold'],
            shadeClose: true, //点击遮罩关闭层
            area: ['1100px', '600px'],
            scrollbar: false,
            content: '${pageContext.request.contextPath}/admin/redPacket_addRandomView.action'
        });
    }
    function receiveLog(sid){
    	layer.open({
            type: 2,
            title: ['领取记录', 'font-weight:bold'],
            shadeClose: true, //点击遮罩关闭层
            area: ['1100px', '520px'],
            scrollbar: false,
            content: '${pageContext.request.contextPath}/admin/redPacket_receiveLog.action?sid='+sid,
            btn: ['关闭'],
            cancel: function (index, layero) {
                layer.close(index);
            }
        });
    };
    function detail(sid){
    	layer.open({
            type: 2,
            title: ['红包详情', 'font-weight:bold'],
            shadeClose: true, //点击遮罩关闭层
            area: ['800px', '650px'],
            scrollbar: false,
            content: '${pageContext.request.contextPath}/admin/redPacket_detailView.action?sid='+sid,
            btn: ['确定'],
            cancel: function (index, layero) {
                layer.close(index);
            }
        });
    }
    function off(sid){
    	
    	layer.confirm('请确认是否下架！', {
    		  btn: ['确认','取消'] //按钮
    		}, function(){
    			$.post("${pageContext.request.contextPath}/admin/redPacket_off.action", {
    		   		'sid': sid
    	         }, function (result) {
    	             data = JSON.parse(result);
    	                 layer.alert(data.msg, function () {
    	                	 window.location.reload(); 
    	                 });
    	         });
    		}, function(){
    		  
    		});
    	
    
   	 }
  	 function sendRedNotes(){
  		window.location.href = "${pageContext.request.contextPath}/admin/redPacket_sendRedNotesView.action";
  	 }
function getNum(f){
	    
	    var f = Math.round(f*100)/100;    
	    var s = f.toString();    
	    var rs = s.indexOf('.');    
	    if (rs < 0) {    
	        rs = s.length;    
	        s += '.';    
	    }    
	    while (s.length <= rs + 2) {    
	        s += '0';    
	    }    
	    return s;
};

</script>
</html>
